function Common(){
	this.ajaxFun=function(url,types,option,callback,asyncType){  //  路径，数据，正确的回调，
	    var async=asyncType?asyncType:true;
	    $.ajax({
	        url:url,
	        type:types,
	        dataType:"json",
	        data:option,
	        async:async,
	        success:function(rs){
	            if($.isFunction(callback)) callback(rs)
	        },
	        error:function(rs){
	            console.log(rs)
	        }
	    })
	}

	this.Geturl=function (){//获取地址栏信息
	    var url =document.location.search.substr(1);
	    var obj={};
	    if(url){
	        var showval=url.split('&');
	        $.each(showval,function(k,v){
	            var arr=v.split('=');
	            var a1=arr[0],
	                a2=arr[1]
	        obj[a1]=a2
	        })
	    }
	    return obj
	}
	this.GetUrlParam=function () {
	    var url =window.location.href; 
	    var thisParam = new Object();
	    // 判断是否存在请求的参数
	    if (url.indexOf("?") != -1) {
	        var str = url.split("?")[1];
	        // 截取所有请求的参数，以数组方式保存
	        strs = str.split("&");
	        for(var i = 0; i < strs.length; i ++) {
	            // 获取该参数名称，值。其中值以unescape()方法解码，有些参数会加密
	            thisParam[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
	        }
	    }
	    // 返回改参数列表对象
	    return thisParam;
	}
	this.setCookie=function(name,value,days){
		var date=new Date().getTime();
		days?days:30; 
		date+=days*24*60*60*1000;
		document.cookie=name+"="+escape(value)+";path=/;expires="+new Date(date).toUTCString();
	}
	this.getCookie=function(name){
			var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
			if(arr!=null)return unescape(arr[2]); return "";
		}

	this.removeCookie=function(name){
		//setCookie(name, 1, -1);
		var date=new Date().getTime()-1;
		document.cookie=name+"="+escape(name)+";path=/;expires="+new Date(date).toUTCString();
	}

	var isNull= /\s/g,
		telNo= /^1(3|4|5|7|8)\d{9}$/,
		email= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/,
		pwd= /(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,16})$/;
	this.checkNull= function(str){//检测是否为空
		if( str == "" ){
			return true;
		}else{
			return false;
		};
		
	}
	this.checkSpace=function(str){//检测是否有空格
		if(isNull.test(str)){
			return true;
		}else{
			return false;
		};
	}
	this.checkUser=function(str){// 检测用户名 
		if( !(telNo.test(str) || email.test(str)) ){
			return true;
		}else {
			return false;
		}
	}
	this.checkPwd=function(str){//检测秘密
		if(!pwd.test(str)){
			return true;
			}else {
				return false;
			}
	}
	
}
var common=new Common();

var token= common.getCookie("token");




var commonFunObj={
	inits:function(){
		this.ajax();
		this.addressFun();
	},
	Interface:{
		getProvince:"http://120.26.199.84/b2b/index.php/Buyer/User/getProvince", //获取省
		getCity:"http://120.26.199.84/b2b/index.php/Buyer/User/getCity",   //获取市
		getArea:"http://120.26.199.84/b2b/index.php/Buyer/User/getArea"  //获取区县
	},
	ajax:function(){
	
	},
	addressFun:function(){
		$("#province p").click(function(){
			common.ajaxFun(commonFunObj.Interface.getProvince,"POST",{},commonFunObj.getProvinceFun); //省
			$("#provinceList").show();
			$("#regionList").hide();
			$(this).addClass("open");
		
		});
		$("#region p").click(function(){
			$("#regionList").show();
			$("#provinceList").hide();
			$(this).addClass("open");
		})

	},
	getProvinceFun:function(res){
		
		var str="",v;
			$.each(res.data,function(k,v){
				str+="<div id="+k+">"+v+"</div>";
			})
			$("#provinceList").html(str);
			$("#provinceList").on("click","div",function(){
				v=$(this).attr("id");
				$("#region p").html("请选择市").addClass("open");
				$("#province p").html($(this).text()).removeClass("open");
				
				$(this).addClass("on").siblings("div").removeClass("on");
				$("#provinceList").hide();
				common.ajaxFun(commonFunObj.Interface.getCity,"POST",{provinceid:v},commonFunObj.getCityFun); //市
			})
	},
	getCityFun:function(res){
		$("#regionList").show();
		var str="",v;
			$.each(res.data,function(k,v){
				str+="<div id="+k+">"+v+"</div>";
			});
			$("#regionList").html(str);

			$("#regionList").on("click","div",function(){
				$("#region p").html($(this).text()).removeClass("open");
				$("#regionList").hide();
				$(this).addClass("on").siblings("div").removeClass("on");
			})
	},
	goodsListFun:function(res){
		if (res.code==1) {
			//alert(res.msg);
		}else {
		var str="";
			$.each(res.data,function(i,v){
				if (typeof v=="object") {
				str+='<li goods_style='+v.goods_style+' goods_id='+v.goods_id+'>'+
					'<div class="imgBox" people_style='+v.people_style+'><img src='+v.image+' alt=""></div>'+
					'<div class="prices">¥'+v.min_price+'</div>'+
					'<div class="introduce">'+v.goods_name+'</div>'+
					'<div class="company" seller_id='+v.seller_id+' brand='+v.brand+'>'+v.seller_name+'</div>'+
					'<div class="productionAddress" prodaddress='+v.prodaddress+'>'+v.shipaddress_name+'</div>'+
				'</li>';
				}
			});
			$("#clothesMain ul").html(str);
			//commonFunObj.pageFun(res);
		};
	}
}	
commonFunObj.inits();
